package com.chen.test3;

public class GoodsTest {
    public static void main(String[] args) {
        // 1.创建一个数组
        Goods[] array = new Goods[3];

        // 2.创建三个商品对象
        Goods g1 = new Goods("001", "电脑", 5000, 10);
        Goods g2 = new Goods("002", "鼠标", 20, 50);
        Goods g3 = new Goods("003", "游艇", 500, 5);

        // 3.将商品对象，保存到数组中
        array[0] = g1;
        array[1] = g2;
        array[2] = g3;

        // 4.遍历数组
        for (int i = 0; i < array.length; i++) {
            // i 表示数组中的索引  array[i] 索引处的元素
            Goods goods = array[i];  // 将数组中索引为i的元素赋值给变量goods，即获取当前遍历到的商品对象
            System.out.println(goods.getId() + " " + goods.getName() + " " + goods.getPrice() + " " + goods.getCount());
        }
    }
}
